// ==UserScript==
// @namespace qiuc12-chrome-adapt
// @name ICBC Assist
// @description ICBC for form element ID access support. Use with ActiveX plugins.
// @match https://*.icbc.com.cn/*
// ==/UserScript==

function executeScriptInClient(command) {
    var codediv = document.createElement("button");
    codediv.setAttribute("style", "display:hidden");
    codediv.setAttribute("onclick", command);
    document.body.appendChild(codediv);
    codediv.click();
    document.body.removeChild(codediv);
}

function checkForm(obj) {
    var parent = obj.parentNode;
    while (parent.nodeType == 1) {
        if (parent.nodeName.toLowerCase() == "form") {
             command = "document.all." + parent.name + "." + obj.id +
                 " = document.all." + obj.id + ";";
             executeScriptInClient(command);
        }
        parent = parent.parentNode;
    }
}

function replaceAll() {
    var objs = document.getElementsByTagName("object");
    for (var i = 0; i < objs.length; ++i) {
        checkForm(objs[i]);
    }
}()